/*
 * @Author: weidewei
 * @Date: 2025-10-31 18:05:13
 * @LastEditors: weidewei
 * @LastEditTime: 2025-10-31 18:25:17
 * @Description: 
 * @FilePath: \2025-front-face\js\node-eventloop.js
 */
// ​题目1（nextTick vs 微任务优先级 输出：start,end,nextTick1,promise1,nextTick2
// console.log('start');

// process.nextTick(() => console.log('nextTick1'));
// Promise.resolve().then(() => {
//   console.log('promise1');
//   process.nextTick(() => console.log('nextTick2'));
// });

// console.log('end');

// ​题目2（async/await 微任务包装）输出：start,bar start,end,bar end,promise,timeout
// console.log('start');

// async function bar() {
//   console.log('bar start');
//   await Promise.resolve();
//   console.log('bar end');
// }

// bar();
// setTimeout(() => console.log('timeout'), 0);
// Promise.resolve().then(() => console.log('promise'));

// console.log('end');

// 题目3（setImmediate vs setTimeout 执行顺序）​输出：start,end,nextTick,timeout,immediate 错 答案：start,end,nextTick,immediate,timeout
console.log('start');

setTimeout(() => console.log('timeout'), 0);
setImmediate(() => console.log('immediate'));

process.nextTick(() => console.log('nextTick'));

console.log('end');


// 题目4（I/O回调阶段的微任务与setImmediate）输出：start,end,nextTick,timeout,fs callback,promise in io,immediate in io

// const fs = require('fs');

// console.log('start');

// fs.readFile(__filename, () => { // I/O回调（poll阶段）
//   console.log('fs callback');
//   setImmediate(() => console.log('immediate in io'));
//   Promise.resolve().then(() => console.log('promise in io'));
// });

// setTimeout(() => console.log('timeout'), 0);
// process.nextTick(() => console.log('nextTick'));

// console.log('end');

